<template>
	<div class="overdue_disabled_wrapper">
		<div class="form">
			<h4>是否超期未登录账号禁用</h4>
			<el-switch
				v-model="isOverdue"
				active-value="1"
				inactive-value="2"
				@change="handleSaveOverdueConfig"
				:disabled="!$isHasAuth(['48fe287315b74a4ca4bede75293e2987'])"
			></el-switch>
		</div>
		<div class="tips">开启之后，账号设定天数未登录被禁用</div>
		<div class="set" v-if="isOverdue === '1'">
			<span>设定账号</span>
			<sw-number-input v-model="overdueLen" size="mini" :disabled="!$isHasAuth(['48fe287315b74a4ca4bede75293e2987'])"></sw-number-input>
			<font>天，</font>
			<span>未登录超期</span>
			<el-button size="mini" type="primary" v-hasPermi="'48fe287315b74a4ca4bede75293e2987'" @click="handleSaveOverdueConfig">保存</el-button>
		</div>
	</div>
</template>

<script>
import { mapGetters } from 'vuex';
import { updateOverdueSetting } from '@/api/system/tbSysSite';
export default {
	data() {
		return {
			isOverdue: '1',
			overdueLen: ''
		};
	},
	computed: {
		...mapGetters(['siteInfo'])
	},
	mounted() {
		this.isOverdue = this.siteInfo.isOverdue;
		this.overdueLen = this.siteInfo.overdueLen;
	},
	methods: {
		async handleSaveOverdueConfig() {
			let params = { id: this.siteInfo.id, isOverdue: this.isOverdue, overdueLen: this.overdueLen };
			let result = await updateOverdueSetting(params).then((res) => res.data);
			if (result.code === '0') {
				this.$showCustomMessage('success', `保存设置成功`);
				this.$store.dispatch('getSiteBaseInfo');
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.overdue_disabled_wrapper {
	display: flex;
	flex-direction: column;
	flex: 1;
	padding: 16px;
	overflow: hidden;
	.form {
		display: flex;
		align-items: center;
		h4 {
			margin-right: 10px;
			line-height: 1;
		}
	}
	.tips {
		font-size: 14px;
		line-height: 1;
		color: #909399;
		margin-top: 10px;
	}
	.set {
		display: flex;
		align-items: center;
		margin-top: 12px;
		span {
			margin-right: 10px;
		}
		font {
			margin-left: 10px;
		}
		.el-input__inner {
			padding: 0 10px;
		}
		.el-input {
			width: 60px;
			font-size: 14px;
			text-align: center;
		}
		.el-button {
			margin-left: 10px;
		}
	}
}
</style>
